home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: OVPAGE.C,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:16 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
- #include "BTREEPAGE.h"
- #include "OVPAGE.h"
- #include "sm_macro.h"
-
-
- void OVPAGE::Init(PID& pid, int es)
- {
- ovCtrl.elCnt = 0;
- ovCtrl.elSize = es;
- ovCtrl.maxEl = OV_DATASIZE / es;
- ovCtrl.selfID = pid;
- ovCtrl.next = ovCtrl.prev = NULLPID;
- }
-
- //
- // Class : OVPAGE
- // Method : void Linkup(OVPAGE* rightPage)
- // Description : Link this page to rightPage. Update next and prev pointers.
- //
- void OVPAGE::Linkup(OVPAGE* rightPage)
- {
- ovCtrl.next = NULLPID;
- if (rightPage) {
- rightPage->ovCtrl.prev = ovCtrl.selfID.page;
- ovCtrl.next = rightPage->ovCtrl.selfID.page;
- }
- }
-
-
-
- //
- // Class : OVPAGE
- // Method : void Shift(int start, OVPAGE* destPage)
- // Description : Shifts all tuples from this page starting
- // from slot 'start' to end of destPage.
- //
- void OVPAGE::Shift(int start, OVPAGE* destPage)
- {
- int cnt = ElCnt() - start; // # of oids to move
-
- //
- // Assert sane parameters
- //
- ASSERT3(start >= 0 && start < ElCnt());
- ASSERT3(destPage->ElCnt() + cnt < MaxEl());
- ASSERT3(destPage->ElSize() == ElSize());
-
- //
- // Move it
- //
- void* op1 = destPage->Get(destPage->ovCtrl.elCnt);
- void* op2 = Get(start);
- BCOPY(op2, op1, ElSize() * cnt);
-
- //
- // Update control info
- //
- destPage->ovCtrl.elCnt += cnt;
- ovCtrl.elCnt = start;
-
- ASSERT3(CheckPage());
- ASSERT3(destPage->CheckPage());
- }
-
-
- void OVPAGE::FillSort(int cnt, void* array)
- {
- ASSERT3(ovCtrl.elCnt == 0);
-
- BCOPY(array, Get(0), cnt * ElSize());
- ovCtrl.elCnt = cnt;
-
- Sort();
-
- ASSERT3(CheckPage());
- }
-
-
- //
- // Class : OVPAGE
- // Method : void Insert(int startSlot, int cnt, void* array)
- // Description : Insert cnt entries of 'array' into this page starting
- // at startSlot.
- //
- void OVPAGE::Insert(int startSlot, int cnt, const void* array)
- {
- ASSERT3(startSlot >= 0 && startSlot <= ElCnt());
-
- //
- // Make space in oidArray
- //
- if (ElCnt() > startSlot) {
- BCOPY(Get(startSlot), Get(startSlot + cnt),
- (ElCnt() - startSlot) * ElSize());
- }
-
- //
- // Copy into the space in oidArray
- //
- BCOPY(array, Get(startSlot), cnt * ElSize());
-
- //
- // Update control info
- //
- ovCtrl.elCnt += cnt;
-
- ASSERT3(CheckPage());
- }
-
-
- //
- // Class : OVPAGE
- // Method : void Remove(int startSlot, int cnt)
- // Description : Remove cnt entries starting from startSlot
- //
- void OVPAGE::Remove(int startSlot, int cnt)
- {
- ASSERT3(cnt > 0);
- ASSERT3(ElCnt() >= startSlot + cnt);
-
- //
- // Close the gap in oidArray
- //
- if (ElCnt() > startSlot + cnt) {
- BCOPY(Get(startSlot + cnt), Get(startSlot),
- (ElCnt()-(startSlot+cnt)) * ElSize());
- }
-
- //
- // Update control info
- //
- ovCtrl.elCnt -= cnt;
- ASSERT3(CheckPage());
- }
-
-
-
- //
- // Class : OVPAGE
- // Method : void Sort()
- // Description : Sort the oidArray. A hack is needed in order to
- // use the qsort() library routine. The static variable
- // __OVSortElSize is used for this purpose.
- //
-
- static int __OVSortElSize = 0;
- static int cmp(const void* o1, const void* o2);
-
-
- void OVPAGE::Sort()
- {
- __OVSortElSize = ElSize(); // used by cmp()
- qsort(Get(0), ElCnt(), ElSize(), cmp);
- }
-
-
- static int cmp(const void* o1, const void* o2)
- {
- ASSERT3(__OVSortElSize > 0 && __OVSortElSize <= SM_MAXELEMLEN);
- return BT_ElemDiff(__OVSortElSize, o1, o2);
- }
-
-
-
- //
- // Class : OVPAGE
- // Method : CheckPage()
- // Description : Checks the content of the page
- //
- int OVPAGE::CheckPage()
- {
- ASSERT1(ElCnt() >= 0);
- for (int i = 0; i < ElCnt() - 1; i++) {
- ASSERT1(BT_ElemDiff(ElSize(), Get(i), Get(i+1)) < 0);
- }
-
- return TRUE;
- }
-